package com.example.check.service.serviceImpl;

import com.example.check.mapper.ItemOverviewMapper;
import com.example.check.pojo.ItemOverview;
import com.example.check.service.ItemOverviewService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 物品总览服务实现类
 */
@Service
public class ItemOverviewServiceImpl implements ItemOverviewService {
    
    @Autowired
    private ItemOverviewMapper itemOverviewMapper;
    
    @Override
    public List<ItemOverview> getAll(Integer userId) {
        if (userId == null) {
            return itemOverviewMapper.getPublicItems();
        }
        return itemOverviewMapper.getAll(userId);
    }
    
    @Override
    public ItemOverview getById(Integer id) {
        return itemOverviewMapper.getById(id);
    }
    
    @Override
    public List<ItemOverview> getByCategoryId(Integer categoryId) {
        return itemOverviewMapper.getByCategoryId(categoryId);
    }
    
    @Override
    public List<ItemOverview> getByName(String name) {
        return itemOverviewMapper.getByName(name);
    }
    
    @Override
    public boolean add(ItemOverview itemOverview) {
        return itemOverviewMapper.add(itemOverview) > 0;
    }
    
    @Override
    public boolean update(ItemOverview itemOverview) {
        return itemOverviewMapper.update(itemOverview) > 0;
    }
    
    @Override
    public boolean deleteById(Integer id) {
        return itemOverviewMapper.deleteById(id) > 0;
    }
    
    @Override
    public int count() {
        return itemOverviewMapper.count();
    }
    
    @Override
    public int countByCategoryId(Integer categoryId) {
        return itemOverviewMapper.countByCategoryId(categoryId);
    }
    
    @Override
    public List<ItemOverview> getFilteredItems(Integer userId, String categoryCode, String keyword) {
        if (userId == null) {
            userId = 0; // 默认值，不会匹配任何用户自定义物品
        }
        return itemOverviewMapper.getFilteredItems(userId, categoryCode, keyword);
    }
}


